import { Col, message, Row, Spin } from 'antd';
import { ItemType } from 'antd/lib/menu/hooks/useItems';
import React, { useEffect, useMemo } from 'react';
import { connect } from 'umi';
import '../common/styles.less';
import { VersionManageContext } from '../model';
import { SchemaManage } from '@/components/SchemaComponent';
import { VersionManageService } from '../services';
import { VersionViewAPI } from '../common/type';
import { VersionCollapse } from './VersionCollapse';
import { VersionInput } from './VersionInput';
const VersionView: React.FC<VersionViewAPI.IVersionViewManage> = ({
  curRes,
  userInfo,
}) => {
  const prefixCls = 'version-collapse-';

  const schemaManageRef: any = React.useRef();

  /** 获取管理页面上下文内容 */
  const {
    loading,
    pagination,
    searchList,
    data,
    refreshRequest,
    manageTableParams,
  } = VersionManageService(curRes);

  useEffect(() => {
    let params = {
      page: 1,
      rows: 10,
      versionType: 2, //PC端
      isPublics: '1,2',
    };
    refreshRequest(params);
  }, []);

  /** 点击搜索重置按钮 */
  const onReset = (requestParams: any) => {
    let params = {
      ...requestParams,
      versionType: 2, //PC端
    };
    refreshRequest(params);
  };

  /** 点击搜索提交按钮 */
  const onSearch = (requestParams: VersionViewAPI.IVersionViewTable) => {
    let params = {
      ...requestParams,
      versionType: 2, //PC端
    };
    refreshRequest(params);
  };

  return (
    <VersionManageContext.Provider
      value={{
        prefixCls,
        curRes,
        userInfo,
        loading,
      }}
    >
      <SchemaManage
        ref={schemaManageRef}
        searchProps={{
          switchList: [], //头部切换列表
          searchList: [], //搜索表单列表
          onReset, //重置
          onSwitch: () => {}, //头部切换
          onSearch, //搜索方法
        }}
        actionList={[]} //Table头部操作按钮列表
        tableProps={{
          // table 表格属性
          // columns,
          // dataSource: data?.rows,
          // loading: loading,
          // pagination: pagination as any,
          // rowKey: 'id',
          // onPageChange: onPageChange, //分页change方法
          noShowColumns: true,
        }}
        tableRenderProps={{
          otherTableCol: true,
          component: (
            <VersionCollapse versionList={data?.rows} loading={loading} />
          ),
        }}
        searchRenderProps={{
          otherSearchForm: true,
          component: (
            <div style={{ padding: '.6rem', width: 400, float: 'right' }}>
              <VersionInput refreshRequest={refreshRequest} />
            </div>
          ),
        }}
      />
    </VersionManageContext.Provider>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  userInfo: baseLogin?.userInfo,
}))(VersionView);
